package webmarket.controller.transferobjects;

import java.sql.Timestamp;
import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import webmarket.common.XmlBase;
import webmarket.model.Merchandise;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class MerchandiseTO extends XmlBase {
	public static List<MerchandiseTO> convert(List<Merchandise> from) {
		List<MerchandiseTO> result = new LinkedList<MerchandiseTO>();
		for (Merchandise merch : from) {
			result.add(new MerchandiseTO(merch));
		}
		return result;
	}

	private static final long serialVersionUID = 5571456522803206332L;

	private int id;
	private int price;
	private String name;
	private ShopcategoryTO category;
	private Timestamp lastchange;
	private String username;
	private String description;

	public MerchandiseTO(Merchandise merchandise) {
		this.id=merchandise.getId();
		this.price = merchandise.getPrice();
		this.name = merchandise.getName();
		this.category = new ShopcategoryTO(merchandise.getCategory());
		this.setLastchange(merchandise.getLastchange() == null ? merchandise.getCreated() : merchandise.getLastchange());
		this.setUsername(merchandise.getUser().getUsername());
		this.description=merchandise.getDescription();
	}

	/**
	 * @return the price
	 */
	public int getPrice() {
		return price;
	}

	/**
	 * @param price
	 *            the price to set
	 */
	public void setPrice(int price) {
		this.price = price;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the lastchange
	 */
	public Timestamp getLastchange() {
		return lastchange;
	}

	/**
	 * @param lastchange
	 *            the lastchange to set
	 */
	public void setLastchange(Timestamp lastchange) {
		this.lastchange = lastchange;
	}

	/**
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * @param username
	 *            the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * @return the category
	 */
	public ShopcategoryTO getCategory() {
		return category;
	}

	/**
	 * @param category
	 *            the category to set
	 */
	public void setCategory(ShopcategoryTO category) {
		this.category = category;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
}
